<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <meta name="renderer" content="webkit">
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="Cache-Control" content="no-cache">
    <meta http-equiv="Expires" content="0">
    <link rel="stylesheet" href="../../css/style.css">
    <title>发货</title>
    <style>

        strong{
            color: rgb(61, 57, 57);
        }
        h5 strong{
            color: #ff0000;
        }
        label{
            vertical-align: top;
            font-weight: normal;
        }

        .modal-dialog{
            background-color: #ffffff;
        }
        #modal1 .modal-body{
            width: 300px;
            margin: 0 auto;
        }
       .modal-conent{border: 1px solid #999999;}
        .dropdown{display: inline-block;}
        button.dropdown-toggle,button.dropdown-toggle:hover,button.dropdown-toggle:focus{background-color: #ffffff;color: #000;}
       .modal-body form .form-group label{width: 80px;}
       .modal-body form .form-group button{border: 1px solid #999;width: 176px;height: 27px;padding: 3px;text-align: center;}
       .table-bordered ul li{display: inline-block;list-style-type: none;}
       .tab-pane table tr th,td{text-align: center;}
       .tdleft tr td,th{text-align: left;}
       table{margin-top: 10px;}
       tr th{font-weight: normal;}
       .thli ul{height: 25px;}
       .thli ul li{ padding: 10px;}
       .modal-backdrop.fade.in{opacity: 0;}
       #deliverBtn{width: 120px;height:60px;margin:0 auto;}
       #deliverBtn button{width: 100px; height: 50px;border-radius: 5px;font-size: 16px;}
       .goodsImage , .goodsImage img{width: 100px;height: 100px;}

    </style>
</head>
<body>
    <div class="configNav"></div>
    <!-- content -->
    <div class="container-fluid">
        <div class="row">
            <!-- left -->
            <div class="col-md-2">
                <div class="list-group">
                    <a href="order_index.html" class="list-group-item ">交易订单</a>
                    <a href="deliver_index.html" class="list-group-item active">发货</a>
                    <a href="address.html" class="list-group-item ">发货设置</a>
                    <a href="evaluate_admin.html" class="list-group-item ">评价管理</a>
                </div>
            </div>
            <!-- right -->
            <div class="col-md-10">
                <ol class="breadcrumb">
                    <li><a href="">商家管理中心</a></li>
                    <li><a href="">订单物流</a></li>
                    <li class="active"><a href="">发货</a></li>
                </ol>
                <div id="deliverOrder">
                </div>

                </div>

            </div>
        </div>
    <script src="../../js/jquery.min.js" charset="utf-8"></script>
    <script src="../../js/bootstrap.min.js" charset="utf-8"></script>
    <script src="../../plugin/layer/layer.js" charset="utf-8"></script>
    <script src="../../plugin/bootstrap-datetimepicker/js/bootstrap-datetimepicker.js" charset="utf-8"></script>
    <script src="../../plugin/bootstrap-datetimepicker/js/bootstrap-datetimepicker.zh-CN.js" charset="utf-8"></script>
    <script src="../../plugin/wangEditor/release/wangEditor.min.js" charset="utf-8"></script>
    <script src="../../js/nav.js" charset="utf-8"></script>
    <script src="../../js/common.js" charset="utf-8"></script>
    <script src="../../js/bootstrap-paginator.js" charset="utf-8"></script>
    <script src="../../js/ajax.js" charset="utf-8"></script>

    <script>
		var storeAddressId =0;
        $(document).ready(function(){
            getExpressOrder()
        })
        var orderDetailId=window.location.href.split("=")[1];//订单id

        // var orderDetailId=319;
        //获取数据
        function getExpressOrder(){
        var pageUrls =  cncbk_common_tools.serverURL + '/business/order/getExpressOrder';
        data ={
                'orderDetailId':orderDetailId
            }
        var func = function (res){
            $('#deliverOrder').empty();
            
            storeAddressId = res.data.storeAddressId;
            var html='';
                html +='<div>'+
            '<button type="submit"  style="margin:10px;" class="ri orderPrint" orderDetailId="'+ orderDetailId+'"><i class="glyphicon glyphicon-print"></i>打印发货单</button>'+
            '<h5><strong>第一步</strong>  确认收货信息及交易详情</h5>'+
            '</div>'+
            '<table class="table table-bordered tdleft">'+
            '<thead>'+
            '<tr>'+
            '<th colspan="2" class="thli">'+
            '<ul>'+
            '<li>订单编号：<span class="orderSn">'+res.data.orderSn+'</span></li>'+
            '<li>下单时间：<span class="orderTime">'+res.data.orderTime+'</span></li>'+
            '</ul>'+
            '</th>'+
            '</tr>'+
            '</thead>'+
            '<tbody>'+
            '<tr>'+
            '<td class="col-md-5" >'+
            '<ul>'+
            '<li class="goodsImage"><img src="http://axyhpic.oss-cn-zhangjiakou.aliyuncs.com/'+ res.data.goodsImage +'" alt=""></li>'+
            '<li><span><a href="http://47.92.118.122/html/wytx/goods_particulars.html?id='+res.data.goodsId +' " class="goodsName">'+res.data.goodsName+'</a></span><br>'+
            '<span>￥<strong class="goodsPrice">'+res.data.goodsPrice+'</strong>x<span class="goodsQuantity">'+res.data.goodsQuantity+'</span>件</span>'+
            '</li>'+
            '</ul>'+
            '</td>'+
            '<td class="col-md-6 " class="tdli">'+
            '<ul >'+
            '<li style="display:block;">运费：<span>'+res.data.goodsFreight+'元</span></li>'+
            '<li style="display:block;">发货备忘：'+
            '<div class="form-group">'+
            '<label for=""></label>'+
            '<textarea name="" id="deliverBz" cols="80" rows="5"  data-toggle="tooltip" title=\'您可以输入一些发货备忘信息（仅卖家自己可见）\'></textarea>'+
            '</div>'+
            '</li>'+
            '</ul>'+
            '</td>'+
            '</tr>'+
            '<tr>'+
            '<td colspan="2">'+
            '收货人信息：'+res.data.name+'<span style="margin:0px 10px;">'+res.data.phone+'</span><span style="margin:0px 10px;">'+res.data.province+res.data.city+res.data.country+res.data.town+res.data.address+'</span>'+
            '</td>'+
            '</tr>'+
            '</tbody>'+
            '</table>'+
            '<div>'+
            '<h5><strong>第二步</strong>  确认发货信息</h5>'+
            '</div>'+
            '<table class="table table-bordered tdleft">'+
            '<tbody>'+
            '<tr>'+
            '<td>';
            if (res.data.storeAddressId > 0) {
            	html+=  '我的发货信息：<span class="deliverinfo" >'+res.data.storeSellerName+'</span><span style="margin:0px 10px;">'+res.data.storeTelphone+'</span><span style="margin:0px 10px;">'+res.data.storeAreaInfo+res.data.storeAddress+'</span>';
            }else if(res.data.storeAddressId == 0){
            	html+= '我的发货信息：<span class="deliverinfo">还未设置发货地址，请进入发货设置 > 地址库中添加</span>';
            }
			html+=
            '<button class="btn-revise ri reviseBtn" data-toggle="modal" data-target="#modal2"><i class="glyphicon glyphicon-pencil"></i>选择</button>'+
            '<div class="modal fade" id="modal2"  aria-labelledby="modal2" aria-hidden="true">'+
            '<div class="modal-dialog">'+
            '<div class="modal-conent">'+
            '<div class="modal-header">'+
            '<button type="button" class="close" data-dismiss="modal" aria-hidden="true">X</button>'+
            '<h4 class="modal-title" id="modaladdress">选择发货地址</h4>'+
            '</div>'+
            '<div class="modal-body">'+
            '<table class="table table-striped">'+
            '<thead>'+
            '<tr>'+
            '<th>发货人</th>'+
            '<th>发货地址</th>'+
            '<th>电话</th>'+
            '<th>操作</th>'+
            '</tr>'+
            '</thead>'+
            '<tbody class="addressBox">'+
            '</tbody>'+
            '</table>'+
            '</div>'+
            '<div class="modal-footer">'+
            '</div>'+
            '</div>'+
            '</div>'+
            '</div>'+
            '</td>'+
            '</tr>'+
            '</tbody>'+
            '</table>'+
            '<div>'+
            '<h5><strong>第三步</strong>  选择物流服务</h5>'+
            '</div>'+
            '<div >'+
            '<div  class="tab-pane active" role="tabpanel"   >'+
            '<table class="table table-bordered" >'+
            '<thead>'+
            '<tr class="cen">'+
            '<th >物流公司名称</th>'+
            '<th>物流单号</th>'+
            '</tr>'+
            '</thead>'+
            '<tbody>'+
            '<tr>'+
            '<td>'+
            '<div class="form-group">'+
            '<input type="text"  id="expressCompany" data-toggle="tooltip" data-placement="right" title=\'请填写物流公司名称\'>'+
            '</div>'+
            '</td>'+
            '<td>'+
            '<div class="form-group">'+
            '<input type="text"   id="expressNumber" data-toggle="tooltip" data-placement="right" title=\'正确填写物流单号，确保快递跟踪查询信息正确\'>'+
            '</div>'+
            '</td>'+
            '</tr>'+
            '</tbody>'+
            '</table>'+
            '<div id="deliverBtn" >'+
            '<button class="btn-success DetermineDeliver" storeAddressId="'+res.data.storeAddress+'">确认发货</button>'+
            '</div>'+
            '</div>'+
            '</div>';
            $('#deliverOrder').append(html);

              //打印发货单跳转
              $('.orderPrint').click(function(){
                window.location.href = "order_print.html?orderDetailId="+ $(this).attr('orderDetailId');
            })

               //编辑按钮获取数据
                $('.reviseBtn').click(function(){
                    var pageUrls = cncbk_common_tools.serverURL + '/business/store/queryAddress';
                    var orderDetailId=window.location.href.split("=")[1];//订单id

                    data={'orderDetailId':orderDetailId}

                    var func = function(res){
                        $('.addressBox').empty()
                       var html='';
                       for (var k = 0; k < res.data.list.length; k++) {
                          html+= '<tr>'+
                        '<td class="sellerName'+res.data.list[k].addressId +'">'+res.data.list[k].sellerName+'</td>'+
                        '<td class="deliverAddress'+res.data.list[k].addressId +'">'+res.data.list[k].areaInfo+res.data.list[k].address+'</td>'+
                        '<td class="telphone'+res.data.list[k].addressId +'">'+res.data.list[k].telphone+'</td>'+
                        '<td> <button  class="choiceAddress" addressId="'+res.data.list[k].addressId +'">选择</button></td>'+
                        '</tr>';

                       }
                       $('.addressBox').append(html);
                        //选择地址按钮
                        $('.choiceAddress').click(function(){
                            storeAddressId =$(this).attr('addressId');//记录编号，地址id
                            var sellerName =$('.sellerName'+storeAddressId ).html();//发货人
                            var deliverAddress =$('.deliverAddress' +storeAddressId).html();//发货地址
                            var telphone =$('.telphone'+storeAddressId).html();//发货电话
                            var deliverinfo = sellerName+''+ deliverAddress +''+ telphone;
                            $('.deliverinfo').html(deliverinfo);
                                $('.close').click();
                            })
                        }
                        ajax(
                            pageUrls,
                            data,
                            func,
                            'post',
                            'json'
                        ) 
                    })
                         //确定发货按钮
                    $('.DetermineDeliver').click(function(){
                            var pageUrls = cncbk_common_tools.serverURL + '/business/order/deliverOrder';
                            var deliverBz=$('#deliverBz').val()
                      
//                          var storeAddressId =$('.choiceAddress').attr('addressId');
//                             if($('.deliverinfo').html() == "还未设置发货地址，请进入发货设置 > 地址库中添加"){
//                                 storeAddressId="";
//                             }else{
//                                 storeAddressId = $('.deliverinfo').html();
//                             }
							if(storeAddressId==0){
								layer.msg('请选择发货地址');
								return;
							}
                            var expressCompany = $('#expressCompany').val();
                            if (expressCompany == '') {
                            	layer.msg('物流公司不能为空');
                            	return;
                            }
                            var expressNumber = $('#expressNumber').val();
                             if (expressNumber == '') {
                            	layer.msg('物流单号不能为空');
                            	return;
                            }
                            console.log(storeAddressId)
                            data={
                                'orderDetailId':orderDetailId,
                                'deliverBz':deliverBz,
                                'storeAddressId':storeAddressId,
                                'expressCompany':expressCompany,
                                'expressNumber':expressNumber
                            }

                            var funSubmit = function (res){
                            	layer.msg(res.msg)
                               if (res.code==200) {
                                window.location.href = "deliver_see.html?orderDetailId="+orderDetailId;
                               }

                            }
                            ajax(
                                pageUrls,
                                data,
                                funSubmit,
                                'post',
                                'json'
                            )
                        })

             
            }

            ajax(
                pageUrls,
                data,
                func,
                'post',
                'json'
                )


        }

    </script>
</body>
</html>
